3 // Copyright (C) 2005 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file types_traits.hpp
42 * Contains a traits class of types used by containers.
45 #ifndef TYPES_TRAITS_HPP
46 #define TYPES_TRAITS_HPP
48 #include <ext/pb_assoc/data_type.hpp>
49 #include <ext/pb_assoc/detail/type_utils.hpp>
58 template<typename Data, class Allocator>
59 struct basic_data_types_traits
65 typename Allocator::template rebind<
66 Data>::other::value_type
70 typename Allocator::template rebind<
75 typename Allocator::template rebind<
76 Data>::other::const_pointer
80 typename Allocator::template rebind<
81 Data>::other::reference
85 typename Allocator::template rebind<
86 Data>::other::const_reference
91 template<typename Data, class Allocator>
92 struct data_types_traits : public basic_data_types_traits<
99 typedef Data given_data_type;
103 #define PB_ASSOC_CLASS_T_DEC \
104 template<class Allocator>
106 #define PB_ASSOC_CLASS_C_DEC \
111 template<class Allocator>
112 struct data_types_traits<
114 Allocator> : public basic_data_types_traits<
121 typedef null_data_type given_data_type;
125 #undef PB_ASSOC_CLASS_T_DEC
127 #undef PB_ASSOC_CLASS_C_DEC
129 template<class Cntnr, class Allocator>
130 struct data_types_traits<
133 Allocator> : public basic_data_types_traits<
140 typedef compound_data_type< Cntnr> given_data_type;
144 #define PB_ASSOC_CLASS_T_DEC \
145 template<typename Key, typename Data>
147 #define PB_ASSOC_CLASS_C_DEC \
148 exception_throw_types_traits< \
152 template<typename Key, typename Data>
153 struct exception_throw_types_traits
158 typedef int_to_type<false> no_throw_copies_false_indicator;
160 typedef int_to_type<true> no_throw_copies_true_indicator;
165 key_no_throw = is_simple_type<Key>::value,
166 data_no_throw = is_same_type<Data, null_data_type>::value ||
167 is_simple_type<Data>::value,
168 no_throw_copies = key_no_throw&& data_no_throw
171 typedef int_to_type<no_throw_copies> no_throw_copies_t;
174 static no_throw_copies_t s_no_throw_copies_indicator;
178 typename PB_ASSOC_CLASS_C_DEC::no_throw_copies_t
179 PB_ASSOC_CLASS_C_DEC::s_no_throw_copies_indicator;
181 #undef PB_ASSOC_CLASS_T_DEC
183 #undef PB_ASSOC_CLASS_C_DEC
185 template<typename Key, typename Data, class Allocator>
186 struct value_types_traits
192 typename Allocator::template rebind<
193 std::pair<const Key, Data> >::other
194 value_type_allocator;
196 typedef typename value_type_allocator::value_type value_type;
198 typedef typename value_type_allocator::pointer pointer;
200 typedef typename value_type_allocator::const_pointer const_pointer;
202 typedef typename value_type_allocator::reference reference;
204 typedef typename value_type_allocator::const_reference const_reference;
208 template<typename Key, class Allocator>
209 struct value_types_traits<
218 typename Allocator::template rebind<
220 value_type_allocator;
222 typedef typename value_type_allocator::value_type value_type;
224 typedef typename value_type_allocator::const_pointer pointer;
226 typedef typename value_type_allocator::const_pointer const_pointer;
228 typedef typename value_type_allocator::const_reference reference;
230 typedef typename value_type_allocator::const_reference const_reference;
234 template<typename Key, class Cntnr, class Allocator>
235 struct value_types_traits<
244 typename Allocator::template rebind<
245 std::pair<const Key, Cntnr> >::other
246 value_type_allocator;
250 typedef typename value_type_allocator::value_type value_type;
252 typedef typename value_type_allocator::pointer pointer;
254 typedef typename value_type_allocator::const_pointer const_pointer;
256 typedef typename value_type_allocator::reference reference;
258 typedef typename value_type_allocator::const_reference const_reference;
262 template<typename Key, typename Data, class Allocator>
263 struct types_traits : public data_types_traits<
266 public value_types_traits<
270 public exception_throw_types_traits<
277 typedef typename Allocator::template rebind<Key>::other key_allocator;
279 typedef typename key_allocator::value_type key_type;
281 typedef typename key_allocator::pointer key_pointer;
283 typedef typename key_allocator::const_pointer const_key_pointer;
285 typedef typename key_allocator::reference key_reference;
287 typedef typename key_allocator::const_reference const_key_reference;
291 } // namespace detail
293 } // namespace pb_assoc
295 #endif // #ifndef TYPES_TRAITS_HPP